<?php
/*
 * estudo de padrões de projetos com php
 * author: fabricio s costa
 * version: 1.0
 * site: http://fabriciojf.com
 */

require_once('com/fabriciojf/security/Permission.class.php');
require_once('com/fabriciojf/persistence/PostDAO.class.php');
class Menu {
    public static function getMenuOn() {

        if (Permission::isInRole(array('admin'))) {
            return array('<a href=do.php?action=Home>Home</a>',
                   '<a href="do.php?action=PainelControle">Painel de Controle</a>',
                   '<a href="do.php?action=CadastroPost">Novo Post/Page</a>',
                   '<a href="do.php?action=Logout">Logout</a>');
        } else if (Permission::isInRole(array('usuario'))) {
            return array('<a href=do.php?action=Home>Home</a>',
                '<a href="do.php?action=PainelControle">Painel de Controle</a>',
                   '<a href="do.php?action=Logout">Logout</a>');
        } else {
            return array('<a href="do.php?action=PainelControle">Login</a>');
        }

    }

    public static function getMenuPost() {
        $postDao =  new PostDAO();
        $posts = $postDao->listAll(0, 10);

        $logado = Permission::isInRole(array('admin'));
        foreach ($posts as $rowMenu){
            if ($logado) {
                $menu[] = '<a href=do.php?action=LerPost&idPost=' .
                $rowMenu->getId() . '>'.$rowMenu->getTitulo() . ' </a>' .
            '<a href=do.php?action=EdicaoPost&idPost=' .
                $rowMenu->getId() . '><b>(Editar)</b></a>';
            } else {
                $menu[] = '<a href=do.php?action=LerPost&idPost=' .
                $rowMenu->getId() . '>'.$rowMenu->getTitulo() . '</a>';
            }
        }

        return $menu;
    }

    public static function getMenuPages() {
        $postDao =  new PostDAO();
        $pages = $postDao->listAllPages();

        $logado = Permission::isInRole(array('admin'));
        foreach ($pages as $rowMenu){
            if ($logado) {
                $menupg[] = '<a href=do.php?action=LerPost&idPost=' .
                $rowMenu->getId() . '>'.$rowMenu->getTitulo() . ' </a>' .
            '<a href=do.php?action=EdicaoPost&idPost=' .
                $rowMenu->getId() . '><b>(Editar)</b></a>';
            } else {
                $menupg[] = '<a href=do.php?action=LerPost&idPost=' .
                $rowMenu->getId() . '>'.$rowMenu->getTitulo() . '</a>';
            }
        }
        return $menupg;
    }

    public static function getMenuPostInativos() {
        $postDao =  new PostDAO();
        $posts = $postDao->listAllPostsInativos(0, 10);

        $logado = Permission::isInRole(array('admin'));
        if ($logado) {
            foreach ($posts as $rowMenu){
                $menuinat[] = '<a href=do.php?action=LerPost&idPost=' .
                $rowMenu->getId() . '>'.$rowMenu->getTitulo() . ' </a>' .
                    '<a href=do.php?action=EdicaoPost&idPost=' .
                $rowMenu->getId() . '><b>(Editar)</b></a>';
            }
        }

        return $menuinat;
    }

    public static function getMenuTicket() {

        if (Permission::isInRole(array('usuario'))) {
            return array('<a href=do.php?action=TicketListar>Listar Tickets</a>',
                   '<a href="do.php?action=TicketCriar">Novo Ticket</a>');
        } else if (Permission::isInRole(array('admin'))) {
            return array('<a href=do.php?action=TicketListar>Listar Tickets</a>');
        }
    }

    public static function getMenuSuperior() {
        $menu =
        '<ul id="sddm">' .
        '                <li><a href="do.php?action=Home">Home</a></li>' .
        '                <li><a href="#" ' .
        '                           onmouseover="mopen(\'m1\')"' .
        '                           onmouseout="mclosetime()">Postagens</a>' .
        '                    <div id="m1"' .
        '                         onmouseover="mcancelclosetime()"' .
        '                         onmouseout="mclosetime()">' .
        '                        <a href="do.php?action=CadastroPost">Novo Post/Page</a>' .
        '                        <a href="#">Listar Post</a>' .
        '                    </div>' .
        '                </li>' .
        '                <li><a href="#"' .
        '                           onmouseover="mopen(\'m2\')"' .
        '                           onmouseout="mclosetime()">Páginas</a>' .
        '                    <div id="m2"' .
        '                         onmouseover="mcancelclosetime()"' .
        '                           onmouseout="mclosetime()">';
        
        $postDao =  new PostDAO();
        $pages = $postDao->listAllPages();
        foreach ($pages as $page) {
            $menu .= '<a href=do.php?action=EdicaoPost&idPost=' .
                $page->getId() . '>'.$page->getTitulo() . ' </a>';
        }
        
        $menu .=
        '                    </div>' .
        '                </li>' .
        '                <li><a href="#" ' .
        '                           onmouseover="mopen(\'m3\')"' .
        '                           onmouseout="mclosetime()">Tickets</a>' .
        '                    <div id="m3"' .
        '                         onmouseover="mcancelclosetime()"' .
        '                         onmouseout="mclosetime()">' .
        '                        <a href="do.php?action=TicketListar">Listar Tickets</a>' .
        '                    </div>' .
        '                </li>' .
        '                <li><a href="mailto:fabriciojf@gmail.com">Contato</a></li>' .
        '                <li><a href="do.php?action=Logout">Sair</a></li>' .
        '            </ul>' ;
        return $menu;
    }
}
?>
